package com.smart.five.ioc.annotation.function;

import com.smart.five.ioc.annotation.LoginDao;
import com.smart.five.ioc.annotation.UserMessageDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

/**
 * user Service
 *
 * @author junrui.wang
 * @create 2018/6/14
 */
@Service("userService")
public class UserSetService {

    private UserMessageDao userMessageDao;

    private LoginDao loginDao;

    //类方法进行标注
    @Autowired
    @Qualifier("userMessageDao") // 多个匹配的bean时，可以指定bean的名称
    public void setUserMessageDao(UserMessageDao userMessageDao) {
        this.userMessageDao = userMessageDao;
    }

    @Autowired(required = false) //可以找不到对应的bean，true时必须要有对应的bean，不然会抛错
    public void setLoginDao(LoginDao loginDao) {
        this.loginDao = loginDao;
    }

    //有多个入参, spring允许对方法入参标注@Qualifier指定bean
    @Autowired
    public void init(@Qualifier("userMessageDao") UserMessageDao userMessageDao, LoginDao loginDao){
        this.loginDao = loginDao;
        this.userMessageDao = userMessageDao;
    };

    //建议在方法上标注@Autowired， 方便测试
}
